﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace SharpSoft.WPF.Controls
{
    /// <summary>
    /// 延时触发按钮，用户点击后会延迟一段时间才触发点击事件
    /// </summary>
    public class DelayButton : Button
    {
        protected async override void OnClick()
        {
            await Task.Delay(this.Delay);
            base.OnClick();
        }



        public TimeSpan Delay
        {
            get { return (TimeSpan)GetValue(DelayProperty); }
            set { SetValue(DelayProperty, value); }
        }

        public static readonly DependencyProperty DelayProperty =
            DependencyProperty.Register("Delay", typeof(TimeSpan), typeof(DelayButton), new PropertyMetadata(TimeSpan.FromSeconds(0.5)));


    }
}
